import request from '@/utils/request'

export const getFile = (id) => {
    return request.get('/file/meta/select/' + id)
}

export const getRootId = () => {
    return request.get('/file/folder/root')
}

export const addFile = (file,parentid) => {
    const formData = new FormData()
    formData.append("file",file)
    return request.post('/file/meta/add',formData,{
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        params: {
            parentid
        }
    })
}

export const addDirectory = (form) => {
    return request.post('/file/folder/create',form)
}

export const previewFile = (id) => {
    return request.get('/file/meta/preview/' + id)
}

export const downloadFile = (id) => {
    return request.get('/file/meta/download/' + id,{
        responseType: 'blob'
    })
}

export const removeFile = (id) => {
    return request.delete('/file/meta/delete/' + id)
}

export const removeFolder = (id) => {
    return request.delete('/file/folder/delete/' + id)
}

export const renameFolder = (form) => {
    return request.post('/file/folder/rename',form)
}

export const authFolder = (id,auth) => {
    return request.post('/file/folder/authority',null,{
        params: {
            folderid: id,
            authority: auth
        }
    })
}

export const authFile = (id,auth) => {
    return request.post('/file/meta/permission',null,{
        params: {
            fileid: id,
            permission: auth
        }
    })
}

export const shareFile = () => {
    return request.get('/file/share')
}

export const fileShareUser = (type,id) => {
    return request.get('/file/share/user',{
        params: {
            type,
            id
        }
    })
}

export const fileShareAddUser = (form) => {
    return request.post('/file/share/adduser',form)
}

export const fileShareRemove = (form) => {
    return request.delete('/file/share/user',{
        data: form
    })
}

export const fileMistakeFolder = () => {
    return request.get('/file/mistake/folder')
}

export const fileMistake = (folderid) => {
    return request.get('/file/mistake/' + folderid)
}

export const fileMistakePreview = (fileid) => {
    return request.get('/file/mistake/preview/' + fileid)
}

export const fileShare = (id) => {
    return request.get('/file/share/' + id)
}

export const ChangeshareFile = (form) => {
    return request.put('/file/share',form)
}

export const fileMistakeFile = (file,folderid) => {
    const formData = new FormData()
    formData.append("file",file)
    return request.post('/file/mistake/file',formData,{
        params: {
            folderid
        }
    })
}

export const fileMistakeFolderCreate = (folderName) => {
    return request.post('/file/mistake/folder',{
        folderName
    })
}

export const fileMistakeFileRemove = (fileid) => {
    return request.delete('/file/mistake/file/' + fileid)
}

export const fileMistakeFolderRemove = (folderid) => {
    return request.delete('/file/mistake/folder/' + folderid)
}

export const fileSharePreview = (fileid) => {
    return request.get('/file/share/preview/' + fileid)
}

export const fileRecycle = () => {
    return request.get('/file/recyclebin/recycle')
}

export const fileRecycleRemove = (fileid) => {
    return request.delete('/file/recyclebin/' + fileid)
}

export const fileRecycleClear = () => {
    return request.delete('/file/recyclebin/empty')
}

export const fileRecycleFind = (fileid) => {
    return request.post('/file/recyclebin/retrieval/' + fileid)
}

export const aiAnalyze = (message,fileId) => {
    return request.post('/file/ai/analyse',{
        message,
        fileId
    })
}

export const getFileTree = (hostuserid) => {
    return request.get('/file/open/all/' + hostuserid)
}

export const previewOpenFile = (fileid,hostuserid) => {
    return request.get('/file/open/preview',{
        params: {
            fileid,
            hostuserid
        }
    })
}